home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Menus / frontierMenu.tcl < prev    next >
Encoding:
Text File  |  1997-12-08  |  21.7 KB  |  794 lines  |  [TEXT/ALFA]

  1. ## -*-Tcl-*-
  2.  # ###################################################################
  3.  #  Frontier menu - tools for using Alpha as Frontier's external editor
  4.  # 
  5.  #  FILE: "frontierMenu.tcl"
  6.  #                                    created: 97-04-03 22.01.22 
  7.  #                                last update: 97-11-02 22.41.03 
  8.  #  Author: Johan Linde
  9.  #  E-mail: <jl@theophys.kth.se>
  10.  #     www: <http://bach.theophys.kth.se/~jl/Alpha.html>
  11.  #  
  12.  # Version: 2.1.1
  13.  # 
  14.  # Copyright 1997 by Johan Linde
  15.  #  
  16.  # Much of the tcl code and the Frontier scripts have been written by 
  17.  # Danis Georgiadis <dmg@hyper.gr>
  18.  # 
  19.  # This software may be used freely, and distributed freely, as long as the 
  20.  # receiver is not obligated in any way by receiving it.
  21.  #  
  22.  # If you make improvements to this file, please share them!
  23.  # 
  24.  # ###################################################################
  25.  ##
  26.  
  27.  
  28. alpha::menu frontierMenu 2.1.1 "•142" in_menu {
  29.     set frontierScriptMenu •144
  30. } uninstall {
  31.     removeFile $pkg_file
  32.     removeFile "$HOME:Help:Frontier Help"
  33. } maintainer {
  34.     "Johan Linde" jl@theophys.kth.se <http://www.theophys.kth.se/~jl/Alpha.html>
  35. } help {file "Frontier Help"}
  36.  
  37. proc frontierMenu {} {}
  38.  
  39.  
  40. # Preferences
  41. newPref f autoLaunch 0 Fron
  42. newPref v BrowsePoints {{root root} {Websites user.websites}} Fron
  43. newPref v OpenPoints {{Websites user.websites} {Glossary user.html.glossary} {Templates user.html.templates}} Fron
  44.  
  45. # Register hooks
  46. hook::register closeHook frontierCloseHook
  47. hook::register savePostHook frontierSavePostHook
  48. hook::register saveasHook frontierSaveasHook
  49.  
  50.  
  51. proc frontierBrowseMenu {} {
  52.     global FronmodeVars
  53.     set bl {}
  54.     foreach b $FronmodeVars(BrowsePoints) {
  55.         lappend bl [lindex $b 0]
  56.     }
  57.     return [list menu -n Browse -p frontierMenuProc -m [concat $bl [list "(-" "Browse at…" Add… Remove…]]]
  58. }
  59.  
  60. proc frontierOpenMenu {} {
  61.     global FronmodeVars
  62.     set bl {}
  63.     foreach b $FronmodeVars(OpenPoints) {
  64.         lappend bl [lindex $b 0]
  65.     }
  66.     return [list menu -n Open -p frontierMenuProc -m [concat $bl [list "(-" "Open…" Add… Remove…]]]
  67. }
  68.  
  69. # Menu definition
  70. menu -n $frontierMenu -p frontierMenuProc -m [list \
  71.     "<U<O/FSwitch to Frontier" \
  72.     "<U<O/'View in Browser" \
  73.     "<I<O/YFrontier Shell" \
  74.     [frontierBrowseMenu] \
  75.     [frontierOpenMenu] \
  76.     "Rebuild Scripts Menu" \
  77.     Preferences…]
  78.  
  79. proc frontierMenuProc {menu item} {
  80.     global frontierMenu FronmodeVars
  81.     switch -glob $menu {
  82.         •* {
  83.             switch $item {
  84.                 "Switch to Frontier" {app::launchFore LAND}
  85.                 Preferences {FronmodifyFlags}
  86.                 default {eval frontier[join $item ""]}
  87.             }
  88.         }
  89.         Browse {
  90.             switch $item {
  91.                 "Browse at" {frontierBrowseAt}
  92.                 Add {frontierAddPoint Browse}
  93.                 Remove {frontierRemovePoint Browse}
  94.                 default {
  95.                     foreach b $FronmodeVars(BrowsePoints) {
  96.                         if {[lindex $b 0] == $item} {
  97.                             odbBrowse [lindex $b 1]
  98.                             break
  99.                         }
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.         Open {
  105.             switch $item {
  106.                 Open {frontierOpen}
  107.                 Add {frontierAddPoint Open}
  108.                 Remove {frontierRemovePoint Open}
  109.                 default {
  110.                     foreach b $FronmodeVars(OpenPoints) {
  111.                         if {[lindex $b 0] == $item} {
  112.                             frontierDoScript "edit (@[lindex $b 1])" front
  113.                             break
  114.                         }
  115.                     }
  116.                 }
  117.             }
  118.         }
  119.     }
  120. }
  121.  
  122.  
  123. # Called by Frontier when opening a Frontier text document in Alpha.
  124. proc openFromFrontier {} {
  125.     global frontierWinList win::Modes
  126.     set name [lindex [winNames -f] 0]
  127.     set name0 [stripNameCount $name]
  128.     regsub -all {\[|\]} $name0 {\\&} name0
  129.     if {[lsearch -exact $frontierWinList $name0] < 0} {lappend frontierWinList $name0}
  130. }
  131.  
  132. # If the current document is a Frontier document, it is updated in Frontier.
  133. proc frontierSavePostHook {name} {
  134.     global frontierWinList
  135.     if {[lsearch -exact $frontierWinList $name] >= 0} {
  136.         app::launchBack LAND
  137.         regsub -all {\\([][])} $name {\1} name
  138.         AEBuild 'LAND' ALFA FMod "----" "“${name}”"
  139.     }
  140. }
  141.  
  142.  
  143. # A list of windows opened from Frontier.
  144. if {![info exists frontierWinList]} {set frontierWinList {}}
  145.  
  146. # Executes a script in Frontier.
  147. proc frontierDoScript {script {front 0} {alert 1}} {
  148.     app::launchBack LAND
  149.     if {[catch {dosc -c 'LAND' -s $script} returnvalue]} {
  150.         if {$alert} {
  151.             alertnote "Frontier $returnvalue"
  152.             error "Frontier $returnvalue"
  153.         }
  154.         error $returnvalue
  155.     } elseif {$front == "front"} {
  156.         switchTo 'LAND'
  157.     }
  158.     return $returnvalue
  159. }
  160.  
  161. # Executes one of the scripts in Frontier, which are required to use Alpha with Frontier.
  162. proc frontierDoAlphaScript {script} {
  163.     global HOME frontierHasWarned
  164.     if {[catch {frontierDoScript $script 0 0} res]} {
  165.         if {![info exists frontierHasWarned]} {
  166.             alertnote "The Frontier verbs required to integrate Alpha and Frontier have not been\
  167.               properly installed. See the file 'Frontier Help.'"
  168.             edit -r -c "$HOME:Help:Frontier Help"
  169.         }
  170.         error $res
  171.     }
  172.     return $res
  173. }
  174.  
  175.  
  176. # closeHook
  177. # If the window to be closed is a Frontier document, it is removed
  178. # from Frontier's list of open external documents.
  179. proc frontierCloseHook {name} {
  180.     global frontierWinList frontierQSWin frontierCommandHistory frontierCommandNum
  181.     if {[set where [lsearch -exact $frontierWinList $name]] >= 0} {
  182.         regsub -all {\\([][])} $name {\1} name
  183.         set frontierWinList [lreplace $frontierWinList $where $where]
  184.         catch {AEBuild 'LAND' ALFA FCls "----" "“${name}”"}
  185.     }
  186.     if {$name == $frontierQSWin} {set frontierCommandHistory ""; set frontierCommandNum 0}
  187. }
  188.  
  189. # saveasHook
  190. proc frontierSaveasHook {oldname newname} {
  191.     global frontierWinList
  192.     # Modify the Frontier win list if it's a Frontier window,
  193.     # and notify Frontier about it.
  194.     if {[set where [lsearch -exact $frontierWinList $oldname]] >= 0} {
  195.         set frontierWinList [lreplace $frontierWinList $where $where $newname]
  196.         app::launchBack LAND
  197.         AEBuild 'LAND' ALFA FMod "----" "“${oldname}”" zzzz "“${newname}”"
  198.     }
  199. }
  200.  
  201.  
  202. # Does the same as 'View in Browser' in Frontier's web menu.
  203. proc frontierViewinBrowser {} {
  204.     global frontierWinList
  205.     if {![llength [winNames]]} {
  206.         alertnote "No window!"
  207.         return
  208.     }
  209.     if {[lsearch $frontierWinList [set name [stripNameCount [lindex [winNames -f] 0]]]] >= 0} {
  210.         if {[winDirty]} {
  211.             if {[set ask [askyesno -c "Save '[file tail $name]'?"]] == "yes"} {
  212.                 save
  213.             } elseif {$ask == "cancel"} {
  214.                 return
  215.             }
  216.         }
  217.         frontierDoAlphaScript "Alpha.viewInBrowser(\"$name\")"
  218.     } else {
  219.         alertnote "Not a Frontier window."
  220.     }
  221. }
  222.  
  223. # Open a window in Frontier
  224. proc frontierOpen {} {
  225.     if {![catch {frontierGetAddress} addr]} {
  226.         frontierDoScript "edit (@$addr)" front
  227.     }
  228. }
  229.  
  230. # Browse a table in Frontier
  231. proc frontierBrowseAt {} {
  232.     if {![catch {frontierGetAddress} addr]} {
  233.         odbBrowse $addr
  234.     }
  235. }
  236.  
  237. # Add to Browse and Open submenus
  238. proc frontierAddPoint {type} {
  239.     global FronmodeVars modifiedModeVars
  240.     set values ""
  241.     while {1} {
  242.         set values [dialog -w 450 -h 130 -t "Add $type menu item" 30 10 290 30 \
  243.             -t "Location in database:" 10 40 160 60 -e [lindex $values 0] 165 40 440 55 \
  244.             -t "Menu text:" 78 70 160 90 -e [lindex $values 1] 165 70 440 85 \
  245.             -b OK 20 100 85 120 -b Cancel 105 100 170 120]
  246.         if {[lindex $values 3]} {return}
  247.         set addr [string trim [lindex $values 0]]
  248.         if {$addr == ""} {alertnote "Location is database must be specified."; continue}
  249.         set text [string trim [lindex $values 1]]
  250.         if {$text == ""} {alertnote "The menu item must be specified."; continue}
  251.         if {[frontierDoScript "defined($addr)"] == "true"} {
  252.             set ex 0
  253.             foreach b $FronmodeVars(${type}Points) {
  254.                 if {[lindex $b 0] == $text} {alertnote "A menu item '$text' already exists."; set ex 1}
  255.             }
  256.             if {!$ex} {break}
  257.         } else {
  258.             alertnote "“$addr” is not a valid database address."
  259.         }
  260.     }
  261.     lappend FronmodeVars(${type}Points) [list $text $addr]
  262.     lappend modifiedModeVars [list ${type}Points FronmodeVars]
  263.     eval [eval frontier${type}Menu]
  264. }
  265.  
  266. # Remove from Browse and Open submenus.
  267. proc frontierRemovePoint {type} {
  268.     global FronmodeVars modifiedModeVars
  269.     set points {}
  270.     foreach b $FronmodeVars(${type}Points) {
  271.         lappend points [lindex $b 0]
  272.         set pointat([lindex $b 0]) [lindex $b 1]
  273.     }
  274.     if {![llength $points] || [catch {listpick -p "Select [string tolower $type] point to remove:" -l $points} points] ||
  275.         ![llength $points]} {return}
  276.     set points [lindex $points 0]
  277.     if {[askyesno "'$points' points to '$pointat($points)'. Remove?"] != "yes"} {return}
  278.     set n {}
  279.     foreach b $FronmodeVars(${type}Points) {
  280.         if {[lindex $b 0] != $points} {lappend n $b}
  281.     }
  282.     set FronmodeVars(${type}Points) $n
  283.     lappend modifiedModeVars [list ${type}Points FronmodeVars]
  284.     eval [eval frontier${type}Menu]
  285. }
  286.  
  287. proc frontierGetAddress {} {
  288.     while {1} {
  289.         if {[catch {set addr [prompt "Location in Frontier database:" ""]}]} {
  290.             error ""
  291.         } else {
  292.             set addr [string trimleft [string trim $addr] {@}]
  293.             switch [frontierDoScript "defined($addr)"] {
  294.                 "true"        {return $addr}
  295.                 "false"        {alertnote "“$addr” is not a valid database address"}
  296.                 ""            {error ""}
  297.             }
  298.         }
  299.     }
  300. }
  301.  
  302. proc FronmodifyFlags {} {
  303.     global FronmodeVars modifiedModeVars
  304.     set values [dialog -w 300 -h 110 -t "Frontier Preferences" 30 10 290 30 \
  305.         -c "Launch Frontier at startup" $FronmodeVars(autoLaunch) 10 40 290 60 \
  306.         -b OK 20 80 85 100 -b Cancel 105 80 170 100]
  307.     if {[lindex $values 2]} {return}
  308.     set i -1
  309.     foreach flag [list autoLaunch] {
  310.         global $flag
  311.         incr i
  312.         set val [lindex $values $i]
  313.         if {$FronmodeVars($flag) != $val} {
  314.             set $flag $val
  315.             set FronmodeVars($flag) $val
  316.             lappend modifiedModeVars [list $flag FronmodeVars]
  317.         }
  318.     }
  319. }
  320.  
  321. proc OdbmodifyFlags {} {
  322.     FronmodifyFlags
  323. }
  324.  
  325. proc frontierGetWin {} {
  326.     global frontierWinList frontierWinNum
  327.     if {![info exists frontierWinNum]} {set frontierWinNum 0}
  328.     if {[llength $frontierWinList] == $frontierWinNum} {
  329.         unset frontierWinNum
  330.         return ""
  331.     } else {
  332.         return [lindex $frontierWinList [expr [incr frontierWinNum] - 1]]
  333.     }
  334. }
  335.  
  336. proc frontierCloseAllWindows {} {
  337.     global frontierWinList
  338.     foreach win $frontierWinList {
  339.         regsub -all {\\([][])} $win {\1} win
  340.         bringToFront $win
  341.         setWinInfo dirty 0
  342.         killWindow
  343.     }
  344. }
  345.  
  346. #===============================================================================
  347. # Script menu
  348. # The code to extract a Frontier menu has been written by
  349. # Danis Georgiadis <dmg@hyper.gr>
  350. #===============================================================================
  351.  
  352. proc setFrontierMenuScript {menu item scpt} {
  353.     global frontierMenuScripts
  354.     if {[regexp {&$} $item]} {
  355.         set item [string trimright $item &]
  356.     } else {
  357.         regsub -all {<[BUISEO]} $item "" item
  358.         regsub {/[a-zA-Z]} $item "" item
  359.         regsub -all {[!\^].} $item "" item
  360.     }
  361.     set key [string trimright "$menu$item" …]
  362.     set frontierMenuScripts($key) $scpt
  363. }
  364.  
  365. proc frontierBuildScriptMenu {} {
  366.     global frontierScriptMenu FronmodeVars
  367.  
  368.     set running 0
  369.     foreach    p [processes] {
  370.         if {[lindex $p 1] == "LAND" } {
  371.             set running 1
  372.         }
  373.     }
  374.     if {!$running} {
  375.         if {$FronmodeVars(autoLaunch)} {
  376.             app::launchBack LAND
  377.         } else {
  378.             return
  379.         }
  380.     }
  381.     set sfina [frontierDoAlphaScript "Alpha.getMenuSource()"]
  382.      set ptext [frontierDoAlphaScript "Alpha.getDefsSource()"]
  383.     
  384.     set mtext [list menu -m -n $frontierScriptMenu -p frontierScriptMenuProc $sfina]
  385.     eval $mtext
  386.     eval $ptext
  387.     
  388.     insertMenu $frontierScriptMenu
  389.  
  390. }
  391.  
  392. proc frontierScriptMenuProc {menu item} {
  393.     global frontierMenuScripts frontierScriptMenu
  394.     if {$menu == $frontierScriptMenu} {set menu ""}
  395.     set key "$menu$item"
  396.     frontierDoScript $frontierMenuScripts($key)
  397. }
  398.  
  399. proc frontierRebuildScriptsMenu {} {
  400.     global frontierMenuScripts
  401.     app::launchBack LAND
  402.     frontierDoAlphaScript "Alpha.invalMenuSources()"
  403.     catch {unset frontierMenuScripts}
  404.     frontierBuildScriptMenu
  405. }
  406.  
  407.  
  408. #===============================================================================
  409. #
  410. # Frontier shell
  411. # Some ideas taken from Matlab mode by Stephen Merkowitz
  412. #===============================================================================
  413. set frontierQSWin "* Frontier shell *"
  414. set frontierCommandHistory ""
  415. set frontierCommandNum 0
  416.  
  417. proc frontierFrontierShell {} {
  418.     global frontierQSWin
  419.     
  420.     if {[lsearch [winNames] $frontierQSWin] >= 0} {
  421.         bringToFront $frontierQSWin
  422.     } else {
  423.         new -n $frontierQSWin -m Fron
  424.         setWinInfo -w $frontierQSWin shell 1
  425.         insertText "Welcome to Alpha's Frontier shell\r«» "
  426.     }
  427. }
  428.  
  429.  
  430. proc frontierRunQuickScript {} {
  431.     global frontierCommandHistory frontierCommandNum frontierQSWin
  432.     set pos [getPos]
  433.  
  434.     set ind [string first "«» " [getText [lineStart $pos] [nextLineStart [getPos]]]]
  435.     if {$ind >= 0} {
  436.         set lStart [expr [lineStart $pos]+$ind+2]
  437.         endOfLine
  438.         set scriptName [getText $lStart [getPos]]
  439.         if {[getPos] != [maxPos]} {
  440.             goto [maxPos]
  441.             insertText $scriptName
  442.         }
  443.         
  444.         catch {frontierDoScript $scriptName 0 0} result
  445.         if {[string compare [lindex $frontierCommandHistory [expr [llength $frontierCommandHistory]-1]] $scriptName] != 0} {
  446.             lappend frontierCommandHistory $scriptName
  447.             if {[llength $frontierCommandHistory] > 30} {
  448.                 set frontierCommandHistory [lrange $frontierCommandHistory 1 end]
  449.             }
  450.         }
  451.         set frontierCommandNum [llength $frontierCommandHistory]
  452.         if {[string length $result]} {
  453.             insertText -w $frontierQSWin "\r" $result \r "«» "
  454.         } else {
  455.             insertText -w $frontierQSWin \r "«» "
  456.         }
  457.     } else {
  458.            if {[getPos] == [maxPos]} {
  459.             insertText "«» "
  460.         } else {
  461.             bind::CarriageReturn
  462.         }
  463.     }
  464.     return
  465. }
  466.  
  467.  
  468. proc frontierPrevCommand {} {
  469.     global frontierCommandHistory frontierCommandNum
  470.     
  471.     set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
  472.     if {[set ind [string first "«» " $text]] == 0} {
  473.         goto [expr [lineStart [getPos]] + $ind + 2]
  474.     } else return
  475.  
  476.     incr frontierCommandNum -1
  477.     if {$frontierCommandNum < 0} {
  478.         incr frontierCommandNum
  479.         endOfLine
  480.         return
  481.     }
  482.     set text [lindex $frontierCommandHistory $frontierCommandNum]
  483.     set to [nextLineStart [getPos]]
  484.     if {[lookAt [expr $to-1]] == "\r"} {incr to -1}
  485.     replaceText [getPos] $to $text
  486. }
  487.  
  488.  
  489. proc frontierNextCommand {} {
  490.     global frontierCommandHistory frontierCommandNum
  491.     
  492.     set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
  493.     if {[set ind [string first "«» " $text]] == 0} {
  494.         goto [expr [lineStart [getPos]] + $ind + 2]
  495.     } else return
  496.  
  497.     incr frontierCommandNum
  498.     if {$frontierCommandNum >= [llength $frontierCommandHistory]} {
  499.         incr frontierCommandNum -1
  500.         frontierCancelLine
  501.         return
  502.     }
  503.     set text [lindex $frontierCommandHistory $frontierCommandNum]
  504.     set to [nextLineStart [getPos]]
  505.     if {[lookAt [expr $to-1]] == "\r"} {incr to -1}
  506.     replaceText [getPos] $to $text
  507. }
  508.  
  509. proc frontierCancelLine {} {
  510.     global frontierCommandHistory frontierCommandNum
  511.  
  512.     set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
  513.     if {[set ind [string first "«» " $text]] == 0} {
  514.         goto [expr [lineStart [getPos]] + $ind + 3]
  515.     } else return
  516.     
  517.     set to [nextLineStart [getPos]]
  518.     deleteText [getPos] $to
  519.     
  520.     set frontierCommandNum [llength $frontierCommandHistory]
  521. }
  522.  
  523. proc frontierBol {} {
  524.     set text [getText [lineStart [getPos]] [nextLineStart [getPos]]]
  525.     if {[set ind [string first "«» " $text]] == 0} {
  526.         goto [expr [lineStart [getPos]] + $ind + 3]
  527.     } else {
  528.         goto [lineStart [getPos]]
  529.     }
  530. }
  531.  
  532.  
  533. regModeKeywords -m {«} Fron {}
  534. bind up <z> frontierPrevCommand Fron
  535. bind down <z> frontierNextCommand Fron
  536. bind '\r' frontierRunQuickScript Fron
  537. bind 'u'  <z>  frontierCancelLine  Fron
  538. bind left <c> frontierBol Fron
  539.  
  540. #===============================================================================
  541. # Odb browser
  542. # Written by Danis Georgiadis <dmg@hyper.gr> and modified by me to be integrated 
  543. # with the rest.
  544. #===============================================================================
  545.  
  546. set odbBrowserTabLength 3
  547. set odbBrowserTypeOffset 60
  548.  
  549. proc odbget120Spaces {} {
  550.     set spaces40 "                                        "
  551.     return "$spaces40$spaces40$spaces40"
  552. }
  553.  
  554. proc odbGetIndLevel {indStr} {
  555.     global odbBrowserTabLength
  556.     return [expr [string length $indStr] / $odbBrowserTabLength]
  557. }
  558.  
  559. proc odbGetIndString {indLevel} {
  560.     global odbBrowserTabLength
  561.     return [string range [odbget120Spaces] 0 [expr [expr $indLevel * $odbBrowserTabLength] - 1]]
  562. }
  563.  
  564. proc odbGetNextIndString {thisIndStr} {
  565.     return [odbGetIndString [expr [odbGetIndLevel $thisIndStr] + 1]]
  566. }
  567.  
  568. proc odbBrowseGetLineParts {name type addr level} {
  569.     global odbBrowserTypeOffset
  570.     global odbBrowserTabLength
  571.     
  572.     set indPadPart [odbGetIndString $level]
  573.     set namePart [string trim $name "\t "]
  574.     set typePadSize [expr $odbBrowserTypeOffset - [expr [string length $indPadPart] + [string length $name]]]
  575.     set typePadPart [string range [odbget120Spaces] 0 [expr $typePadSize - 1]]
  576.     set typePart "◊$type◊"
  577.     set addrPart "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$addr∞"
  578.     
  579.     set res ""
  580.     lappend res $indPadPart $namePart $typePadPart $typePart $addrPart
  581.     
  582.     return $res
  583. }
  584.  
  585. proc odbBrowseDown {} {
  586.     set curPos [getPos]
  587.     set curLineStart [lineStart $curPos]
  588.     set curLineEnd [nextLineStart $curPos]
  589.     select $curLineStart $curLineEnd
  590.     
  591.     set newLineStart [nextLineStart $curLineStart]
  592.     set newLineEnd [nextLineStart $newLineStart]
  593.     if {$newLineStart < [maxPos]} {
  594.         select $newLineStart $newLineEnd
  595.     }
  596. }
  597.  
  598. proc odbBrowseCmdDown {{option 0}} {
  599.     set curPos [getPos]
  600.     set curLineStart [lineStart $curPos]
  601.     set curLineEnd [nextLineStart $curPos]
  602.     
  603.     if {[regexp {^( *).+◊tabl◊\t+∞(.+)∞} [getText $curLineStart $curLineEnd] junk ind addr]} {
  604.         if {$option} {killWindow}
  605.         odbBrowse $addr
  606.     }
  607. }
  608.  
  609. proc odbBrowseUp {} {
  610.     set curPos [getPos]
  611.     set curLineStart [lineStart $curPos]
  612.     set curLineEnd [nextLineStart $curPos]
  613.     select $curLineStart $curLineEnd
  614.     
  615.     set newLineStart [prevLineStart $curLineStart]
  616.     set newLineEnd [nextLineStart $newLineStart]
  617.     if {$newLineEnd > 0} {
  618.         select $newLineStart $newLineEnd
  619.     }
  620. }
  621.  
  622. proc odbBrowseCmdUp {{option 0}} {
  623.     regexp {∞(.+)∞} [getText 0 [nextLineStart 0]] junk addr
  624.     if {[set point [string last "." $addr]] >= 0} {
  625.         if {$option} {killWindow}
  626.         odbBrowse [string range $addr 0 [expr $point - 1]]
  627.     }
  628. }
  629.  
  630. proc odbBrowserAddCells {pos cells indLevel} {
  631.     
  632.     set tmp ""
  633.     set colorCodes ""
  634.     set lastPos $pos
  635.     
  636.     foreach cell $cells {
  637.         set cellName [lindex $cell 0]
  638.         set cellType [lindex $cell 1]
  639.         set cellAddr [lindex $cell 2]
  640.         
  641.         set parts [odbBrowseGetLineParts $cellName $cellType $cellAddr $indLevel]
  642.         
  643.         set indPart [lindex $parts 0]
  644.         set namePart [lindex $parts 1]
  645.         set typePartPad [lindex $parts 2]
  646.         set typePart [lindex $parts 3]
  647.         set addrPart [lindex $parts 4]
  648.         
  649.         set nameStart [expr $lastPos + [string length $indPart]]
  650.         set nameEnd [expr $nameStart + [string length $namePart]]
  651.         
  652.         if {$cellType == "TEXT" || $cellType == "wptx"} {
  653.             lappend colorCodes [concat $nameStart 3]
  654.             lappend colorCodes [concat $nameEnd 0]
  655.         } elseif {$cellType == "tabl"} {
  656.             lappend colorCodes [concat $nameStart 5]
  657.             lappend colorCodes [concat $nameEnd 0]
  658.         } else {
  659.             lappend colorCodes [concat $nameStart 1]
  660.             lappend colorCodes [concat $nameEnd 0]
  661.         }
  662.         
  663.         set typeStart [expr $lastPos + [string length $indPart] + [string length $namePart] + [string length $typePartPad]]
  664.         set typeEnd [expr $typeStart + [string length $typePart]]
  665.         lappend colorCodes [concat $typeStart 4]
  666.         lappend colorCodes [concat $typeEnd 0]
  667.         
  668.         set line ""
  669.         append line $indPart $namePart $typePartPad $typePart $addrPart "\n"
  670.         append tmp $line
  671.         
  672.         set lastPos [expr $lastPos + [string length $line]]
  673.     }
  674.     
  675.     select $pos $pos
  676.     setWinInfo read-only 0
  677.     
  678.     insertText $tmp
  679.     
  680.     foreach colorCode $colorCodes {
  681.         insertColorEscape [lindex $colorCode 0] [lindex $colorCode 1]
  682.     }
  683.     
  684.     setWinInfo dirty 0
  685.     setWinInfo read-only 1
  686.     eval sizeWin [lrange [getGeometry] 2 end]
  687. }
  688.  
  689. proc odbBrowseRight {} {
  690.     set curPos [getPos]
  691.     set curLineStart [lineStart $curPos]
  692.     set curLineEnd [nextLineStart $curPos]
  693.     
  694.     if {[regexp {^( *).+◊tabl◊\t+∞(.+)∞} [getText $curLineStart $curLineEnd] junk ind addr]} {
  695.         set nextIndString [odbGetNextIndString $ind]
  696.         set nextLineText [getText [nextLineStart $curLineStart] [nextLineStart [nextLineStart $curLineStart]]]
  697.         if {![regexp "^$nextIndString" $nextLineText junk]} {
  698.             
  699.             set cells [frontierDoAlphaScript "Alpha.getCellData(@$addr)"]
  700.             odbBrowserAddCells $curLineEnd $cells [odbGetIndLevel $nextIndString]
  701.             
  702.         }
  703.     }
  704.     
  705.     select $curLineStart $curLineEnd
  706. }
  707.  
  708. proc odbBrowseLeft {} {
  709.     set curPos [getPos]
  710.     set curLineStart [lineStart $curPos]
  711.     set curLineEnd [nextLineStart $curPos]
  712.     
  713.     if {[regexp {^( *).+∞(.+)∞} [getText $curLineStart $curLineEnd] junk ind elems]} {
  714.         set pos [nextLineStart $curLineStart]
  715.         set start $pos
  716.         set nextIndString [odbGetNextIndString $ind]
  717.         while {[regexp "^$nextIndString" [getText $pos [nextLineStart $pos]] junk]} {
  718.             set pos [nextLineStart $pos]
  719.         }
  720.         setWinInfo read-only 0
  721.         deleteText $start $pos
  722.         setWinInfo dirty 0
  723.         setWinInfo read-only 1
  724.     }
  725.     select $curLineStart $curLineEnd
  726. }
  727.  
  728. proc odbBrowseEditObj {} {
  729.     set curPos [getPos]
  730.     set curLineStart [lineStart $curPos]
  731.     set curLineEnd [nextLineStart $curPos]
  732.     
  733.     if {[regexp {^.+∞(.+)∞} [getText $curLineStart $curLineEnd] junk addr]} {
  734.         frontierDoAlphaScript "Alpha.editCell(@$addr)"
  735.     }
  736. }
  737.  
  738. proc odbBrowse {{addr root}} {
  739.     if {$addr == ""} {
  740.         return
  741.     }
  742.     
  743.     global odbBrowserTypeOffset
  744.     global odbBrowserTabLength
  745.     
  746.     set cell [frontierDoAlphaScript "Alpha.getCellData(@$addr, false)"]
  747.     set wtitle [lindex [lindex $cell 0] 2]
  748.     regsub -all {[][]} $wtitle "" wtitle
  749.     set wtitle "* Frontier “$wtitle” *"
  750.     
  751.     if {[lsearch [winNames] $wtitle] >= 0} {
  752.         bringToFront $wtitle
  753.     } else {
  754.         new -n $wtitle -g 4 42 449 300 -m Odb
  755.         setWinInfo dirty 0
  756.         odbBrowserAddCells 0 $cell 0
  757.         select 0 [nextLineStart 0]
  758.         odbBrowseRight
  759.     }
  760. }
  761.  
  762. bind '\r'        odbBrowseEditObj    Odb
  763. bind enter        odbBrowseEditObj    Odb
  764.  
  765. bind down         odbBrowseDown        Odb
  766. bind down <c>    odbBrowseCmdDown    Odb
  767. bind down <co>    {odbBrowseCmdDown 1}    Odb
  768. bind up            odbBrowseUp            Odb
  769. bind up <c>        odbBrowseCmdUp        Odb
  770. bind up <co>    {odbBrowseCmdUp 1}        Odb
  771. bind right        odbBrowseRight        Odb
  772. bind left        odbBrowseLeft        Odb
  773.  
  774. if {![info exists frontierVersion] || $frontierVersion != 2.1} {
  775.     dialog -w 400 -h 180 -t "Welcome to Frontier menu 2.1.1" 70 10 390 30 \
  776.       -t "Make sure you install all the scripts in the folder 'Frontier verbs' into Frontier.\r\
  777.       If you upgrade from a previous version make sure you install the Frontier verbs which have been updated.\r\
  778.       You find information in the file 'Frontier Help'." 10 50 390 135 \
  779.       -b OK 20 150 85 170
  780.     catch {edit -r -c "$HOME:Help:Frontier Help"}
  781.     addDef frontierVersion 2.1
  782.     set frontierHasWarned 1
  783. }
  784.  
  785.  
  786. catch {frontierBuildScriptMenu}
  787. catch {unset frontierHasWarned}
  788.